from flask import Blueprint,jsonify,request,abort
from flask_restful import Api,Resource
from app.models import *
school_expend0= Api()

class School_Expend1(Resource):
    def get_select(self):
        select = School_Expend.query.all()
        return jsonify({"select": list(map(con6, select))})
    def put(self, uid):
        selec = School_Expend(
            request.json["time"],
            request.json["use"],
            request.json["Payment_Object"],
            request.json["Agent"],
            request.json["Approver"],
            request.json["Cost"],
            request.json["Expenditure_Patterns"],
            request.json["Collection_Objects"],
            request.json["Number"],
            request.json["Petty_Cash"],
            request.json["Remarks"],

        )
        db.session.add(selec)
        db.session.commit()
        return jsonify({"selec": con6(selec)}), 201
school_expend0.add_resource(School_Expend1, "/School_Expend1/")


class School_Expend2(Resource):
    def get(self, uid):
        selec = School_Expend.query.filter_by(id=uid).first()
        if selec is None:
            abort(404)
        return jsonify({"selec": con6(selec)})

    def post(self, uid):
        selec = School_Expend(
            request.json["time"],
            request.json["use"],
            request.json["Payment_Object"],
            request.json["Agent"],
            request.json["Approver"],
            request.json["Cost"],
            request.json["Expenditure_Patterns"],
            request.json["Collection_Objects"],
            request.json["Number"],
            request.json["Petty_Cash"],
            request.json["Remarks"],

        )
        db.session.add(selec)
        db.session.commit()
        return jsonify({"selec": con6(selec)}), 201


school_expend0.add_resource(School_Expend2, "/School_Expend2/<int:uid>/")